<template>
	<view class="page_box">
		<view class="head_box " v-if="0">
			<yy-custom bgColor="bg-gradual-blue">
				<block slot="backText">返回</block>
				<block slot="content">导航栏</block>
			</yy-custom>
		</view>

		<view class="content_box">
			<button class="cu-btn addbtn flex align-center  justify-center "
				@click="jump('/pages/personalCtr/addShipAddr')">
				添加收货地址
			</button>
			<scroll-view scroll-y="true" class="scroll-y" v-if="data.length">
				<block v-for="(item, index) in data" :key="index">
					<view class="info margin-top padding bg-white">
						<view class="flex justify-between padding-tb-xs" @tap="goBack(item)">
							<view class="flex align-center">
								<image src="../../static/dz1.png" mode="widthFix"
									style="width: 29rpx ; height: 36rpx ;"></image>
								<text class="margin-left f28">{{ item.name }}</text>
							</view>
							<text class="f26">{{ item.phone }}</text>
						</view>
						<view class="padding-tb f24 solid-bottom">
							{{ item.province }}{{ item.city }}{{ item.county }} {{ item.detail }}
						</view>
						<view class="padding-top-sm flex justify-between align-center">
							<!-- <button class="cu-btn defAddr flex justify-center align-center" v-if="item.isDefault == 1">
								默认地址
							</button> -->
							<view class="flex align-center ">
								<view class="flex align-center" @click="del(item.id)">
									<view class="margin-left-xs f24 ">
										<text class="cuIcon-delete margin-right-xs f24"></text>
										删除
									</view>
								</view>
								<view class="flex align-center margin-left" @click="edt(item)">
									<view class="margin-left-xs f24 ">
										<text class="cuIcon-write margin-right-xs f24"></text>
										编辑
									</view>
								</view>
							</view>
						</view>
					</view>
				</block>
			</scroll-view>
			<image class="fiix " src="https://files.catbox.moe/0vq58p.png" mode="aspectFill" v-else></image>
		</view>
		<view class="foot_box"></view>
		<!-- 登录提示 -->
		<yy-login v-if="false"></yy-login>
		<!-- 加载提示 -->
		<yy-loading text="加载中.." mask="true" click="true" ref="loading"></yy-loading>
		<!-- 信息提示-->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				data: []
			};
		},
		onShow() {
			this.getAddr();
		},
		onLoad(e) {},
		methods: {
			jump(url) {
				console.log('url: ', url);
				uni.navigateTo({
					url
				});
			},
			async getAddr() {
				const res = await this.$u.get('harvestaddress/list/' + uni.getStorageSync('data').id, {}, {});
				this.data = res.data;
			},
			async del(id) {
				console.log('id :>> ', id);
				var that = this;
				if (that.data.length == 1) {
					uni.showModal({
						title: '提示',
						content: '只剩下一个地址 , 确认删除吗 ? ',
						success: function(res) {
							if (res.confirm) {
								that.dell(id);
							} else if (res.cancel) {}
						}
					});
				} else {
					that.dell(id);
				}
			},
			async dell(id) {
				const res = await this.$u.delete('harvestaddress/' + id, {}, {});
				if (res.code == 0) {
					this.$refs.uToast.show({
						title: '删除地址成功',
						type: 'success'
					});
					this.getAddr();
				}
			},
			async edt(item) {
				uni.navigateTo({
					url: 'addShipAddr?item=' + JSON.stringify(item)
				});
			},

			goBack(item) {
				uni.navigateBack({
					delta: 1
				})

				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				prevPage.$vm.searchVal = item; //修改上一页data里面的searchVal参数值为1211

			}
		}
	};
</script>

<style lang="scss" scoped>
	.page_box {
		// width: 100vw;
		// height: 90vh;
		// overflow: scroll;
		background-color: #f7f7f7;

		.fiix {
			position: fixed;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			width: 290rpx;
			height: 270rpx;
		}

		.scroll-y {
			height: 84vh;
		}

		.content_box {
			.scroll {
				height: 100vh;
			}

			.addbtn {
				position: fixed;
				bottom: 54rpx;
				left: 50%;
				transform: translateX(-50%);
				width: 686rpx;
				height: 90rpx;
				background: #92b9b7;
				border-radius: 45rpx;

				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #ffffff;
				z-index: 9;
			}

			.info {
				.defAddr {
					width: 130rpx;
					height: 50rpx;
					background: #fbb03b;
					border-radius: 25rpx;

					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #ffffff;
					white-space: nowrap;
				}
			}
		}
	}
</style>
